package edu.amm.fanal.examples;

import edu.amm.fanal.api.BoundaryProblem;
import edu.amm.fanal.api.Function;
import edu.amm.fanal.api.NonlinearProblem;

/**
 * Примеры нелинейных задач.
 * 
 * @author Иванов Илья
 * @since 2013-05-18
 *
 */
public class NonlinearProblemsExamples {
	
	/**
	 * <b>x'' = [(x')^2 + 1]^(3 / 2), x(0) = -1, x(1) = 0</b>
	 */
	public static final NonlinearProblem EXAMPLE_2 = new NonlinearProblem(0, -1, 1, 0) {
		{
			setF(new Function(NonlinearProblem.F_DIM) {
				
				private Function dfdt = new Function(getDim()) {
					
					protected double getValue(double... x) {
						return 0;
					}
				};
				
				private Function dfdx = new Function(getDim()) {
					
					protected double getValue(double... x) {
						return 0;
					}
				};
				
				private Function dfdxdt = new Function(getDim()) {
					
					protected double getValue(double... x) {
						return 3 * x[2] * Math.sqrt(x[2] * x[2] + 1);
					}
				};
				
				protected double getValue(double... x) {
					double val = x[2] * x[2] + 1;
					val = Math.sqrt(val);
					
					return val * val * val;
				}
				
				protected Function getDerivative(int variableNumber) {
					switch (variableNumber) {
						case 0:
							return dfdt;
						case 1:
							return dfdx;
						case 2:
							return dfdxdt;
						default:
							return null;
					}
				}
			});
			
			setSolution(new Function(BoundaryProblem.SOLUTION_DIM) {
				
				protected double getValue(double... x) {
					double val = - Math.sqrt(1 - x[0] * x[0]);
					return val;
				}
			});
		}
	};
}